<template>
	<view class="pics">
		<scroll-view class="left" scroll-y>
			<view :class="active === index ? 'active' : ''" v-for="(item,index) in cates" :key="item.id" @click="change(index,item.id)">{{item.title}}</view>
		</scroll-view>
		
		<scroll-view class="right" scroll-y>
			<view class="item" v-for="(item,index) in secondData" :key="item.id">
				<image :src="item.img_url"></image>
				<text>{{item.title}}</text>
			</view>
			<text v-if="secondData.length === 0">暂无数据</text>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cates:[],
				active:0,
				secondData:[]
			}
		},
		methods: {
			async getPicCates(){
				const res = await this.$myRequest({
					url: '/api/getimgcategory'
				})
				this.cates = res.data.message;
				this.change(0,this.cates[0].id)
			},
			async change(index,id){
				this.active = index;
				console.log(id)
				//获取右侧的数据
				const res =  await this.$myRequest({
					url: '/api/getimages/' + id
				})
				this.secondData = res.data.message
			}
		},
		onLoad() {
			this.getPicCates();
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.pics{
		display: flex;
		height: 100%;
		.left{
			width: 200rpx;
			height: 100%;
			border-right: 1px solid #eee;
			view{
				height: 60px;
				line-height: 60px;
				color: #333;
				text-align: center;
				font-size: 30rpx;
				border-top: 1px solid #eee;
			}
			.active{
				background-color: $shop-color;
				color: #fff;
			}
		}
		.right{
			width: 100%;
			width: 530rpx;
			margin: 10rpx auto;
			item{
				
				image{
					width: 520rpx;
					height: 520rpx;
					border-radius: 5px;
				}
				text{
					font-size: 30rpx;
					line-height: 60rpx;
				}
			}
		}
	}
</style>
